//
//  HomeViewController.m
//  Painter
//
//  Created by  ibokan on 10-9-7.
//  Copyright 2010 tencent.com. All rights reserved.
//

#import "PainterViewController.h"
#import "PainterView.h"


@implementation PainterViewController






- (id)initWithTitle:(NSString *)title withNavigationTitle:(NSString *)navTitle {
	
	if (self=[super init]) {
		// Custom initialization
		//[[self tabBarItem] setImage:[UIImage imageNamed:@"icon_help.png"]];
		
		self.title = title;
		self.navigationItem.title = navTitle;
	}
	
	return self;
}




/*
 */
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
	/*
	CGRect bounds=[[UIScreen mainScreen] applicationFrame];
	[super loadView];
	textView =[[UITextView alloc] initWithFrame:bounds];
	textView.text=@"TEST";
	[self.view addSubview:textView];	
	[textView release];	
	*/
	
	CGRect bounds=[[UIScreen mainScreen] applicationFrame];
	self.view = [[UIView alloc] initWithFrame:bounds];
	self.view.backgroundColor = [UIColor grayColor];
	
	
	
	
	
	painterView = [[PainterView alloc] initWithFrame:CGRectMake(0.0,0.0,bounds.size.width,bounds.size.height - 138.0)];
	[self.view addSubview:painterView];	
	
	
	toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0,bounds.size.height -138.0,bounds.size.width, 48.0)];
	toolbar.barStyle = UIBarStyleBlack;
	[self.view addSubview:toolbar];	
	
	
	UIBarButtonItem *eraseButton = [[UIBarButtonItem alloc] initWithTitle:@" Erase " 
																	style:UIBarButtonItemStyleBordered
																   target:self
																   action:@selector(erase)];
	
	UIBarButtonItem *clearButton = [[UIBarButtonItem alloc] initWithTitle:@" clear " 
																	style:UIBarButtonItemStyleBordered
																   target:self
																   action:@selector(clear)];
	UIBarButtonItem *finishButton = [[UIBarButtonItem alloc] initWithTitle:@" finish " 
																	 style:UIBarButtonItemStyleBordered
																	target:self
																	action:@selector(finish)];
	UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
																		   target:nil
																		   action:nil];
	
	[toolbar setItems:[NSArray arrayWithObjects:space, eraseButton, clearButton, finishButton,space, nil]];	
	
	
	
	[painterView release];
	[toolbar release];
	[eraseButton release];
	[clearButton release];
	[space release];	
	
	
	
}

/*

-(id) init 
{
	if(self = [super init])
	{
		self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
		self.view.backgroundColor = [UIColor grayColor];
		
		painterView = [[PainterView alloc] initWithFrame:CGRectMake(0, 0, 320, 440)];
		[self.view addSubview:painterView];
		
		toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 440, 320, 40)];
		toolbar.barStyle = UIBarStyleBlack;
		[self.view addSubview:toolbar];
		UIBarButtonItem *eraseButton = [[UIBarButtonItem alloc] initWithTitle:@" Erase " 
																		style:UIBarButtonItemStyleBordered
																	   target:self
																	   action:@selector(erase)];
		
		UIBarButtonItem *clearButton = [[UIBarButtonItem alloc] initWithTitle:@" clear " 
																		style:UIBarButtonItemStyleBordered
																	   target:self
																	   action:@selector(clear)];
		UIBarButtonItem *finishButton = [[UIBarButtonItem alloc] initWithTitle:@" finish " 
																		style:UIBarButtonItemStyleBordered
																	   target:self
																	   action:@selector(finish)];
		UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
																			   target:nil
																			   action:nil];
		
		[toolbar setItems:[NSArray arrayWithObjects:space, eraseButton, clearButton, finishButton,space, nil]];
		[eraseButton release];
		[clearButton release];
		[space release];
		
	}
	
	return self;
}
 
 */

-(void) erase
{
	[painterView erase];
}

-(void) clear
{
	[painterView resetView];
}

-(void) finish
{
	[painterView setColor:[UIColor blackColor]];
}


- (void)dealloc 
{
	[toolbar release];
    [super dealloc];
}


@end
